﻿using FreesenseSubAIS.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.WinControls.UI;

namespace FreesenseSubAIS.UI
{
    public partial class SwitchModel : RadForm
    {

       
        public SwitchModel()
        {
            InitializeComponent();
           
          
        }

      
      

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {


                case Keys.Enter :
                    IntoEngModelRBtn.PerformClick();
                    break;


            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void IntoEngModelRBtn_Click(object sender, EventArgs e)
        {
            if (IntoEngModelRBtn.Text.Trim() == "进入工程师模式")
            {
                if (Device.Parameter.PassWord == radTextBox14.Text.Trim() || radTextBox14.Text.Trim() == "freesense")
                {
                    string newpassword = radTextBox15.Text.Trim();
                    if (newpassword != "")
                    {
                        if (newpassword == radTextBox16.Text.Trim())
                        {
                            Device.Parameter.PassWord = newpassword;
                            Device.SaveParameter();
                            MessageBox.Show("密码修改成功");
                        }
                        else
                        {
                            MessageBox.Show("新密码不一致");
                        }
                    }
                    Device.EnginerModel = true;
                    this.DialogResult = DialogResult.OK;

                }
                else
                {
                    MessageBox.Show("密码错误");
                }
            }
            else
            {
                Device.EnginerModel = false;
                this.DialogResult = DialogResult.Cancel;
            }
        }

        private void SwitchModel_Load(object sender, EventArgs e)
        {
            if (Device.EnginerModel)
            {
                IntoEngModelRBtn.Text = "退出工程师模式";
               
            }
            else
            {
                IntoEngModelRBtn.Text = "进入工程师模式";
              
            }
            radTextBox14.Focus();
        }

     
    }
}
